//
// $Id: BaseTest2.java,v 1.8 2007/05/02 21:34:06 vivaldi Exp $
//
// BUI - a user interface library for the JME 3D engine
// Copyright (C) 2005, Michael Bayne, All Rights Reserved
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

package eMdP.estats;


import com.jme.animation.AnimationController;
import com.jme.math.FastMath;
import com.jme.math.Vector3f;
import com.jme.scene.Node;
import com.jmex.bui.BButton;
import com.jmex.bui.event.ActionEvent;
import com.jmex.bui.event.ActionListener;
import com.jmex.bui.util.Point;

import eMdP.ElMensajeroDePekin;
import eMdP.gestors.GestorConstants;
import eMdP.gestors.GestorModels;
import eMdP.gestors.GestorMusica;
import eMdP.gestors.GestorPantalla;

/**
 * A base class for our various visual tests.
 */
public class MenuPrincipal extends GbuiGameState {
	
	private BButton boto;
    
    public MenuPrincipal(String name)
    {
    	super(name);
    	
    	/* Creem la musica */
    	GestorMusica.CrearMusicaMenus();
    	
    	Node xino = new Node("Xino");
    	xino = GestorModels.getJMEXML(GestorConstants.DIRECCIO_MODELS_PERSONATGES+"xino-jme.xml");
    	GestorModels.afegirTexturaXML(xino, GestorConstants.DIRECCIO_TEXTURES_PERSONATGES+"marro.jpg");
    	xino.setLocalTranslation(4, -6, 0);
    	AnimationController animacio = (AnimationController)xino.getChild("ArmatureSuperBone").getController(0);
		System.out.println(animacio.getAnimations());
		animacio.setActiveAnimation("Caminar");
		animacio.setActive(true);
		animacio.setSpeed(2.5f);
		xino.getLocalRotation().fromAngles(FastMath.DEG_TO_RAD*270f, -FastMath.DEG_TO_RAD*45, 0);
    	rootNode.attachChild(xino);
    	
    	System.out.println("Entro a menú principal");

    	window.setSize((int)(0.8f * 1.2f * display.getWidth() / 2), 
         		(int)(1.4f * (display.getHeight() / 2)));
        //System.out.println("Finestra: "+window);
        int buttonWidth = window.getWidth() / 2;
 		int buttonHeight = 48;
 		int posicioY = window.getHeight()-buttonHeight-5;
 		int posicioX = window.getWidth()/4;
         
 		boto = new BButton("Jugar sol");
 		boto.setPreferredSize(buttonWidth, buttonHeight);
 		boto.addListener(new ActionListener() {
 			@Override
 			public void actionPerformed(ActionEvent event) {
 				System.out.println("Nene, le has dado al play in the sky");
 				GestorPantalla.canvia(0,3);
 			}
         });
         window.add(boto, new Point(posicioX, posicioY));
         
         posicioY = window.getHeight()-buttonHeight*2-5*2;
         boto = new BButton("Jugar en multijugador");
         boto.setPreferredSize(buttonWidth, buttonHeight);
         boto.addListener(new ActionListener() {
 			@Override
 			public void actionPerformed(ActionEvent event) {
 				System.out.println("Nene, le has dado al play together under the blue sky");
 				GestorPantalla.canvia(0,5);
 			}
         });
         window.add(boto, new Point(posicioX, posicioY));
         
         
         posicioY = window.getHeight()-buttonHeight*3-5*3;
         boto = new BButton("Configuració");
         boto.setPreferredSize(buttonWidth, buttonHeight);
         boto.addListener(new ActionListener() {
 			@Override
 			public void actionPerformed(ActionEvent event) {
 				System.out.println("Boton configurar, con mas opciones que el windows Vista!");
 				GestorPantalla.canvia(0,2);
 			}
         });
         window.add(boto, new Point(posicioX, posicioY));
         
         posicioY = window.getHeight()-buttonHeight*4-5*4;
         boto = new BButton("Màximes puntuacions");
         boto.setPreferredSize(buttonWidth, buttonHeight);
         boto.addListener(new ActionListener() {
 			@Override
 			public void actionPerformed(ActionEvent event) {
 				System.out.println("Boton configurar, con mas opciones que el windows Vista!");
 				GestorPantalla.canvia(0,7);
 			}
         });
         window.add(boto, new Point(posicioX, posicioY));
 		
         posicioY = window.getHeight()-buttonHeight*5-5*5;
         boto = new BButton("Credits");
         boto.setPreferredSize(buttonWidth, buttonHeight);
         boto.addListener(new ActionListener() {
 			@Override
 			public void actionPerformed(ActionEvent event) {
 				GestorPantalla.canvia(0, 6);
 			}
         });
         window.add(boto, new Point(posicioX, posicioY));
         
 		// Cancel button
         boto = new BButton("Sortir");
         boto.setPreferredSize(buttonWidth, buttonHeight);
         boto.addListener(new ActionListener() {
 			@Override
 			public void actionPerformed(ActionEvent event) {
 				ElMensajeroDePekin.exit();
 			}
         });
 		window.add(boto, new Point(posicioX, 20));
    }
 
    @Override
    public void cleanup() {
        //Do nothing
    }
 
    @Override
    public void update(float tpf) {
    	super.update(tpf);
    	GestorMusica.update();
		//input.update(tpf);
    }
}
